from PyQt6.QtWidgets import QStatusBar, QLabel, QProgressBar
from PyQt6.QtCore import Qt

class EnhancedStatusBar(QStatusBar):
    def __init__(self):
        super().__init__()
        self.setStyleSheet("""
            QStatusBar {
                border-top: 1px solid #3a3a3a;
                background-color: #2d2d2d;
                color: #cccccc;
            }
            QLabel {
                padding: 2px 8px;
            }
        """)

        # 连接状态
        self.connection_label = QLabel("未连接")
        self.addWidget(self.connection_label)

        # 进度条
        self.progress_bar = QProgressBar()
        self.progress_bar.setMaximumWidth(200)
        self.progress_bar.setVisible(False)
        self.addWidget(self.progress_bar)

        # 添加伸缩空间
        self.addPermanentWidget(QLabel(), 1)

        # 行号列号
        self.position_label = QLabel("行: 1, 列: 1")
        self.addPermanentWidget(self.position_label)

        # 状态消息
        self.message_label = QLabel("就绪")
        self.addPermanentWidget(self.message_label)

    def set_connection_status(self, status):
        """设置连接状态"""
        self.connection_label.setText(status)

    def set_position(self, line, index):
        """设置光标位置"""
        self.position_label.setText(f"行: {line}, 列: {index}")

    def show_message(self, message, timeout=0):
        """显示消息"""
        self.message_label.setText(message)
        if timeout > 0:
            super().showMessage(message, timeout)

    def show_progress(self, visible, value=0, maximum=100):
        """显示或隐藏进度条"""
        self.progress_bar.setVisible(visible)
        if visible:
            self.progress_bar.setValue(value)
            self.progress_bar.setMaximum(maximum)